package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyPNGImage;


import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;

public class PNGImageImplIE6 extends PNGImageImpl {
    private String url;
    private boolean isPng;


    public Element createElement(String url, int width, int height, int opacity) {
        this.url = url;
        Window.alert("url" + url);
        if (url.endsWith(".png") || url.endsWith(".PNG")) {
            isPng = true;
        } else {
            isPng = false;
        }

        if (isPng) {
            Element div = DOM.createDiv();

            // DOM.setInnerHTML(div, "<span style=\"width:"+width+"px;height:"+height+"px;filter:progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+");\"><span style=\"display:inline-block;width:"+width+"px;height:"+height+"px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='" + url + "', sizingMethod='scale')\"></span></span>");

            return div;

        } else {
            return super.createElement(url, width, height, opacity);
        }
    }

    public String getUrl(FPNGImage image) {
        if (isPng) {
            return url;
        } else {
            return super.getUrl(image);
        }
    }

    public void formatElement(FPNGImage image, int width, int height, int opacity) {
        DOM.setElementPropertyInt(image.getElement(), "width", width);
        DOM.setElementPropertyInt(image.getElement(), "height", height);

        DOM.setStyleAttribute(image.getElement(), "display", "inline-block");
        DOM.setStyleAttribute(image.getElement(), "filter", "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='" + image.url + "', sizingMethod='scale')");
        Window.alert(image.toString());
    }
}
/*
<span style="width:400px;height:32px;display:inline-block;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='varyAlpha.png');"><img style="
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);

" src="varyAlpha.png" width="400" height="32" border="0" alt=""></span>
*/